//- Copyright (c) 2016 Lucky Byte, Inc.
each merch in merchs
  .comment
    a.avatar
      i.big.icon.middle.aligned.caret.right.link.black.detail
    .content
      a.author= merch.merno
      .metadata
        span.date 共 #{merch.threads.length} 次变更
        if merch.threads.length > 0
          span.date 最后变更时间: #{merch.threads[0].timestamp.format('YYYY-MM-DD HH:mm:ss')}
      .text= merch.name

    .comments.detail(style="display:none;")
      for thread in merch.threads
        - var icon = ''
        - var action = ''
        case thread.action
          when 'I'
            - icon = 'add green'
            - action = "新增商户"
          when 'U'
            - icon = 'write blue'
            - action = "修改商户"
          when 'D'
            - icon = 'minus orange'
            - action = "删除商户"
          default
            - icon = 'question red'
            - action = '未知'

        .comment.thread(data-collapsed="true")
          a.avatar
            i.large.icon.link.modified(class="#{icon}")
          .content
            a.author #{action} #{thread.new_data.merno}
            .metadata
              span.date= thread.new_data.name
              span.date= thread.timestamp.format('YYYY-MM-DD HH:mm:ss')
            .text
            .actions
              a.reply.modified(href="#") 查看数据差异

            table.ui.table.small.compact.celled.very.basic.modified(
              style="display:none; margin-left:20px;")
              thead
                tr
                  th.collapsing 字段名
                  th.collapsing 变更前
                  th 变更后
              tbody
                -
                  var sys_fields = [
                    'serial', 'uuid', 'ctime', 'trace_num', 'batch_num', 'order_id',
                    'inputer', 'input_time', 'checker', 'check_time',
                    'effect_time', 'shaded'
                  ]

                for field in thread.modified_fields
                  - var klass = 'positive'
                  if sys_fields.indexOf(field.key) >= 0
                    - klass = 'disabled'

                  tr(class="#{klass}")
                    td.collapsing= pay_merch[field.key] || field.key
                    td.collapsing
                      if field.old_v
                        if field.key == 'inputer'
                          = thread.old_input_user || field.old_v
                        else if field.key == 'checker'
                          = thread.old_check_user || field.old_v
                        else if field.key == 'chnl'
                          = constant.merch_chnls[field.old_v]
                        else if field.key == 'fee'
                          = thread.old_fee_name || field.new_v
                        else if field.key == 'mapto_merid'
                          | #{thread.old_mapto_merno || field.new_v} － #{thread.old_mapto_mer_name}
                        else if field.key == 'settl_merid'
                          | #{thread.old_settl_merno || field.new_v} － #{thread.old_settl_mer_name}
                        else
                          = field.old_v
                    td
                      if field.new_v
                        if field.key == 'inputer'
                          = thread.input_user || field.new_v
                        else if field.key == 'checker'
                          = thread.check_user || field.new_v
                        else if field.key == 'chnl'
                          = constant.merch_chnls[field.new_v]
                        else if field.key == 'fee'
                          = thread.fee_name || field.new_v
                        else if field.key == 'mapto_merid'
                          | #{thread.mapto_merno || field.new_v} － #{thread.mapto_mer_name}
                        else if field.key == 'settl_merid'
                          | #{thread.settl_merno || field.new_v} － #{thread.settl_mer_name}
                        else
                          = field.new_v
